# -*- coding: utf-8 -*-
"""
用于循环触发的入口组件
"""

import os
import time
import ppc
import ppc.pipe


class IntervalStartup(ppc.pipe.Pipe):
    """时间间隔循环组件"""

    def send(self, data):
        self._refresh()

        interval = int(self['interval'].value)
        interval *= ppc.SECONDS_NUM[self['unit'].value]

        while True:
            self.transfer(time.time())
            if interval < 0:
                break
            if interval > 0:
                time.sleep(interval)
        
            # 是否循环中止
            if self.flag == ppc.pipe.Flag.Break:
                self.flag = ppc.pipe.Flag.Normal
                break


    def handle(self):
        pass
